<template>
	<view class="reg-page">
		<view style="padding: 0 10px;margin-top: 10px;">
			<view class="form-sty">
				<text class="input-title bi-shu-sty">输入原密码</text>
				<input class="input-sty" type="text" v-model="oldPassword" :maxlength="10" placeholder="请输入原密码">
			</view>
			<view class="form-sty">
				<text class="input-title bi-shu-sty">输入新密码</text>
				<input class="input-sty" type="text" v-model="newPassword" :maxlength="10" placeholder="请输入原密码">
			</view>
			<view class="form-sty">
				<text class="input-title bi-shu-sty">确认新密码</text>
				<input class="input-sty" type="text" v-model="confirmPassword" :maxlength="10" placeholder="请输入原密码">
			</view>
			<view style="display: flex;margin-top: 35px;">
				<view class="btn-area" @click="restBtn">
					<view class="btn-sty">重置</view>
				</view>
				<view class="btn-area" @click="confirmBtn">
					<view class="btn-sty" style="background: #fc993b;color:#fff;">确认</view>
				</view>
			</view>

		</view>
	</view>
</template>

<script>
	import {cheackUser,verifyForm,checkFontRule} from '@/utils/baseFn.js';
	const db = uniCloud.database()
	export default {
		data() {
			return {
				oldPassword: '',
				newPassword: '',
				confirmPassword: ''
			}
		},
		onLoad(e) {
			const _this = this
			uni.getStorage({
				key: 'userInfo',
				success: function(res) {
					if (res.data) {
						const file = res.data.portrait.split(',')
						_this.formData = res.data
					}
				},
				fail: function(res) {
				}
			})
		},
		created() {},
		mounted() {},
		methods: {
			confirmBtn() {
				const _this = this
				if (this.oldPassword !== this.formData.password) {
					uni.showModal({
						content: '原密码不正确',
						showCancel: false
					})
					return
				}
				if (this.newPassword !== this.confirmPassword) {
					uni.showModal({
						content: '新密码二次输入的不一致',
						showCancel: false
					})
					return
				}
				if (this.newPassword.length < 6) {
					uni.showModal({
						content: '密码不得少于6位',
						showCancel: false
					})
					return
				}
				uni.showLoading({mask:true});
				if (this.formData._id) {
					const parm = {password: this.newPassword}
					return db.collection('user-MGMT').doc(this.formData._id).update(parm).then((res) => {
						uni.showToast({
							title: '修改成功'
						})
						uni.removeStorage({
							key: 'userInfo',
							success: function() {
								setTimeout(() => {
									uni.navigateTo({
										url: '../login/login'
									});
								}, 1228)
							}
						})
						uni.hideLoading()
					}).catch((err) => {
						uni.showModal({
							content: err.message || '请求服务失败',
							showCancel: false
						})
						uni.hideLoading()
					})
				} 
			}
		}
	}
</script>

<style>
	.reg-page {}
	.form-sty  .uni-file-picker {
		display: inline-block;
		width: 50%;
	}
	.input-title {
		width: 230rpx;
		display: inline-block;
		vertical-align: top;
	}

	.img-sty {
		width: 60%;
		height: 68px;
		display: inline-block;
	}

	.input-sty {
		display: inline-block;
		vertical-align: middle;
	}
	.is-disabled {
		width: 50%;
		color: #888;
	}
	.form-sty {
		width: 100%;
		height: 70px;
		border-bottom: 1px solid #dcdfe6;
		line-height: 70px;
		padding: 0 5px;
	}

	.btn-area {
		width: 150px;
		text-align: center;
		flex: 1;
	}

	.btn-sty {
		width: 150px;
		height: 38px;
		color: #fc993b;
		background: #ffffff;
		border: 1px solid #fc993b;
		border-radius: 20px;
		line-height: 38px;
		margin: 0 auto;
	}
	.bi-shu-sty::before {
		content: '*';
		position: relative;
		top: 0;
		left: 0;
		color: red;
	}
</style>
<style lang="scss">
</style>